// graceUI/components/graceShade.js
Component({
  properties: {
    background: { type: String, value : "rgba(0, 0, 0, 0.1)" },
    zIndex: { type: Number, value: 1 },
    show: { type: Boolean, value: true }
  },
  data:{
    realShow : false
  },
  methods:{
    closeShade: function() {
      this.triggerEvent('closeShade');
    },
    nottmove:function(){}
  },
  ready : function(){
    this.setData({realShow:this.data.show});
    watch(this, {
      show: function (vn, vo) {
        if (vn) {
          this.setData({realShow : vn});
        } else {
          this.setData({ isOut: true });
          setTimeout(() => { this.setData({ realShow: false });}, 200);
        }
      }
    });
  }
});

function defineReactive(data, key, val, fn) {
  Object.defineProperty(data, key, {
    configurable: true,
    enumerable: true,
    get: function () {return val},
    set: function (newVal) {
      if (newVal === val) return
      fn && fn(newVal)
      val = newVal
    },
  })
}
function watch(ctx, obj) {
  Object.keys(obj).forEach(key => {
    defineReactive(ctx.data, key, ctx.data[key], function (value) {
      obj[key].call(ctx, value)
    })
  })
}
